/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Missile.java]
 * Creation Date        [22-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_03_game.tankwar_local.version_2;

import java.awt.Color;
import java.awt.Graphics;

import pkg_03_game.tankwar_local.version_2.Tank.Direction;

/**
 * 导弹
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Missile {

	/** 导弹速度 */
	public static final int X_SPEED = 10;
	public static final int Y_SPEED = 10;

	/** 导弹坐标 */
	private int x = 0;
	private int y = 0;

	/** 导弹的宽度和高度 */
	public static final int MISSILE_WIDTH = 5;
	public static final int MISSILE_HEIGHT = 5;

	/** 导弹方向, 借助于坦克的方向 */
	Tank.Direction direction;

	public Missile() {
		super();
	}

	public Missile(int x, int y, Direction direction) {
		super();
		this.x = x;
		this.y = y;
		this.direction = direction;
	}

	/**
	 * 绘制导弹
	 * 
	 * @param g
	 */
	public void paint(Graphics g) {
		// 获得原位置颜色
		Color color = g.getColor();
		// 设置导弹颜色
		g.setColor(Color.ORANGE);
		g.fillOval(x, y, MISSILE_WIDTH, MISSILE_HEIGHT);
		// 将前景色还原
		g.setColor(color);
		// 导弹移动
		move();
	}

	/**
	 * 导弹移动
	 */
	private void move() {
		switch (direction) {
		case LEFT:
			x -= X_SPEED;
			break;
		case RIGHT:
			x += X_SPEED;
			break;
		case UP:
			y -= Y_SPEED;
			break;
		case DOWN:
			y += Y_SPEED;
			break;
		default:
			break;
		}
	}
}
